package com.kethink;

import java.math.BigInteger;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.Stack;

/**
 * @Description create by xuxiaojun
 * date: 2018/12/25
 * Time: 16:02
 */
public class LeeCode_7 {

    public static void main(String[] args){

        System.out.println(reverse(1534236469));
    }

    public static int reverse(int i){

        boolean flag = true;
        if(i<0){
            flag = false;
            i = -i;
        }
        String s = String.valueOf(i);
        char[] chars = s.toCharArray();
        Stack stack = new Stack();
        for(char c : chars){
            stack.push(c);
        }
        String result = "";
        while (!stack.empty()){
            result += stack.pop();
        }
        if(result.startsWith("0")){
            result.substring(1,result.length());
        }
        result = result.trim();

        try{
            if(!flag){
                return Integer.valueOf("-"+result);
            }
            return Integer.valueOf(result);
        }catch (Exception e){
            return 0;
        }


    }
}
